﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Ionic.Zip;

namespace Cms.Tests.Unit.Application
{

    [TestClass]
    public class IOTests
    {
    
        [TestMethod]
        public void UnzipFoldersAndFilesTest()
        {
            Directory.CreateDirectory(Environment.CurrentDirectory + "\\SoonToBeZipped");
            StreamWriter sw = File.CreateText(Environment.CurrentDirectory + "\\RootFile.txt");
            sw.WriteLine("root file content");
            sw.Close();
            sw.Dispose();
            sw = File.CreateText(Environment.CurrentDirectory + "\\SoonToBeZipped\\AnotherFile.txt");
            sw.WriteLine("another file content");
            sw.Close();
            sw.Dispose();
            using (ZipFile zip = new ZipFile())
            {
                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                zip.AddFile(Environment.CurrentDirectory + "\\RootFile.txt", "");
                zip.AddFile(Environment.CurrentDirectory + "\\SoonToBeZipped\\AnotherFile.txt", "SoonToBeZipped");
                zip.Save(Environment.CurrentDirectory + "\\test.zip");
            }
            Directory.Delete(Environment.CurrentDirectory + "\\SoonToBeZipped", true);
            File.Delete(Environment.CurrentDirectory + "\\RootFile.txt");
            using (ZipFile zip = ZipFile.Read(Environment.CurrentDirectory + "\\test.zip"))
            {
                foreach (ZipEntry entry in zip)
                {
                    entry.Extract(Environment.CurrentDirectory);
                }
            }
        }

    }

}
